package com.tvunetworks.center.user.service.impl;

import com.tvunetworks.center.user.mapper.GridEventRecordMapper;
import com.tvunetworks.center.user.model.GridEvent;
import com.tvunetworks.center.user.model.GridEventRecord;
import com.tvunetworks.center.user.model.vo.GridEventRecordVo;
import com.tvunetworks.center.user.service.GridEventRecordService;
import com.tvunetworks.center.user.service.GridEventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: tvucc-aggregator
 * @description: GridEventRecordServiceImpl
 * @author lebronchen
 * @create: 2020-01-07 18:51
 **/
@Service
@Slf4j
public class GridEventRecordServiceImpl extends BaseService<GridEventRecord> implements GridEventRecordService{

    @Autowired
    private GridEventService gridEventService;
    @Autowired
    private GridEventRecordMapper gridEventRecordMapper;

    @Override
    public void createRecord(String gridEventId, int operate) {
        GridEventRecord record = new GridEventRecord()
                .setGridEventId(gridEventId)
                .setOperate(operate);
        super.insert(record);
    }

    @Override
    public GridEventRecordVo listEventRecord(String id) {
        GridEvent gridEvent = gridEventService.getByIdContainDeleted(id);
        if (gridEvent == null) {
            return null;
        }

        List<GridEventRecord> list = gridEventRecordMapper.listRecord(id);
        GridEventRecordVo vo = new GridEventRecordVo()
                .setGridEvent(gridEvent)
                .setOperates(list);
        return vo;
    }
}
